#! /bin/bash

# This is from http://kernelreloaded.blog385.com/index.php/archives/madwifi-wireless-for-asus-eee-pc-on-fedora-9-howto/

MADWIFI=madwifi-nr-r3366+ar5007

if [ ! -f "${MADWIFI}.tar.gz" ]; then 
 echo "Attempting to download the wxWidgets source from madwifi snapshots"
 wget http://snapshots.madwifi.org/special/${MADWIFI}.tar.gz
	if [ ! -f "${MADWIFI}.tar.gz" ]; then 
	 echo "Failed to download patched sources - sorry"
		exit 0
	fi
fi

tar xvf ${MADWIFI}.tar.gz

MADWIFI_DIR=`echo "${MADWIFI}" | sed -e 's|-nr-|-ng-|'`

pushd .
cd ${MADWIFI_DIR}
make clean
make

popd

#su
#make install

for i in `find ${MADWIFI_DIR} | grep '.ko$'`; do cp $i .;done
exit 1

# This is the old 'manual patch' version

bunzip2 madwifi-eee.tar.bz2 
tar -xf madwifi-eee.tar 
bzip2 madwifi-eee.tar

pushd .

cd madwifi
tar -xzf madwifi-ng-r2756-20071018.tar.gz 
cd madwifi-ng-r2756-20071018

# Skip the OPTIONAL injection patch
# patch -Np1 -i ../madwifi-ng-r2277.patch 

# This is the important one
patch -Np0 -i ../madwifi-eee.patch 

make clean
make

popd

for i in `find madwifi | grep '.ko$'`; do cp $i .;done
